package com.sharemarking.system.mapper;

import com.sharemarking.wa.common.entity.Post;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface BannerMapper {
    @Select("SELECT * FROM cms_post WHERE channel_id = 13 ORDER BY sort LIMIT #{pageIndex},#{pageSize}")
    List<Post> getPage(Map<String,Object> map);

    @Select("SELECT COUNT(*) FROM cms_post WHERE channel_id = 13 LIMIT #{pageIndex},#{pageSize}")
    int getPageTotal(Map<String,Object> map);

    @Select("SELECT * FROM cms_post WHERE id = #{id}")
    Post getById(Integer id);

    @Insert("INSERT INTO cms_post(cover,title,sort,channel_id,hidden)"
            + "VALUES(#{cover},'首页轮播图',#{sort},13,1)")
    void insert(Post obj);

    @Update("UPDATE cms_post SET cover=#{cover},sort=#{sort} WHERE id = #{id}")
    void update(Post obj);

    @Delete("DELETE FROM cms_post WHERE id = #{id}")
    void delete(int id);
}
